import { http } from "../http";

const baseUrl = "/api/dms/deviceApplications";

// 设备申请状态枚举
export enum ApplicationStatus {
  APPLYING = "APPLYING", // 待审批
  APPROVING = "APPROVING", // 审批中
  APPROVED = "APPROVED", // 已通过
  REJECTED = "REJECTED", // 已拒绝
  CANCELLED = "CANCELLED", // 已取消
}

// 获取用户申请中或者申请通过的设备
export interface SearchRequestType {
  userCode: string;
  applicationStatus: string;
  keyword: string;
  deviceTypeId: string;
  deviceStatus: string;
  location: string;
  belong: string;
  page: number;
  size: number;
}
export const searchAPI = (params: SearchRequestType) => {
  return http.post(`${baseUrl}/search`, params);
};

// 查询用户申请记录详情
export const getUserApplicationRecordsAPI = (applicantCode: string) => {
  return http.get(`${baseUrl}/applicant/${applicantCode}`);
};

// 发起设备申请流程
export interface CreateDeviceApplicationRequest {
  deviceId: string;
  reason: string;
  applicantCode: string;
}
export const createDeviceApplicationAPI = (
  params: CreateDeviceApplicationRequest
) => {
  return http.post(`${baseUrl}/submitApplication`, {
    deviceId: params.deviceId,
    applicantCode: params.applicantCode,
  });
};

/**
 * 获取指定设备申请流程详情（包含审批进度）
 */
export interface AuditProgressType {
  id: string | null;
  stage: string | null;
  stageDescription: string | null;
  status: string | null;
  statusDescription: string | null;
  result: string | null;
  resultDescription: string | null;
  comment: string | null;
  approverCode: string | null;
  approverName: string | null;
  approvalTime: string | null;
  priority: number | null;
}
export const getApplicationDetailAPI = (id: string) => {
  return http.get(`${baseUrl}/${id}`);
};
